{% extends "../templates/ajax/main_content_base.html" %} 
{% block intro %}{% endblock %}
{% block page_name %}create_homework{% endblock %}
{% block content %}

<div class="content-box">
	<div class="content-box-header">
		<h3>发布作业</h3>
	</div>
	<!-- End .content-box-header -->

	<div class="content-box-content">

		<div class="tab-content default-tab">

			<h4></h4>
			<form id="create-homework-form" action="create_homework" method="post">

				<fieldset>
					<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->

					<p>
						<label>作业名称</label> <input
							class="text-input small-input required" type="text" id="name"
							name="name" />
						<!-- Classes for input-notification: success, error, information, attention -->
						<br />
						<small>您的要发布的作业的名称</small>
					</p>
					
					<p>
						<label>作业类型</label> <select name="type"
							class="small-input required">
							<option value="personal">个人作业</option>
							<option value="team">小组作业</option>
						</select>
						<br />
						<small>作业由个人完成还是小组完成</small>
					</p>
					<p>
						<label>截止日期</label> <input
							class="text-input small-input required" readonly type="text" id="deadline"
							name="deadline" />
						<br />
						<small>作业的截止日期</small>
					</p>
					<p>
						<label>作业内容</label>
						<textarea class="content" id="content"
							name="content" ></textarea>
							
						<br />
						<small>作业的详细内容</small>
					</p>
					<p>
						<input class="button" type="submit" value="发布" />
					</p>

				</fieldset>

				<div class="clear"></div>
				<!-- End .clear -->

			</form>

		</div>
		<!-- End #tab3 -->

	</div>
	<!-- End .content-box-content -->

</div>


<script type="text/javascript" >
$('.content').attr("id", $(this).attr("id") + "_" + Math.random()).ckeditor();
$('#deadline').datepicker();
$('#create-homework-form').validate();
$('#create-homework-form').ajaxForm({
    // dataType identifies the expected content type of the server response
    dataType: 'json',

    // success identifies the function to invoke when the server response
    // has been received
    success:function(json)
    {
    	if(json.error)
    		{
    			if(json.error_type=="HomeworkDuplicationError")
					Boxy.alert("作业名已经存在，请更换另一个", function() {}, {title: '错误'});
    			else
    				Boxy.alert("创建错误，请检查您的信息\n"+json.error_type+json.error, function() {}, {title: '错误'});
    		}
    	else
    		Boxy.alert("作业创建成功", function() {
    			alert('show_homework?homework='+json.homework);
    			$('#main-content').load('show_homework?homework='+json.homework)
    		}, {title: '成功'});
    }
});
</script>
{% endblock %}



